package com.scienzeinternazionali.util;

import java.util.regex.*;
import org.apache.log4j.Logger;


public class RegexValidate {

    private static final String nameClass = "RegexValidate";
	private static Logger logger = LogFactory.getLogger(LogFactory.SCIENZEINTERNAZIONALI);
	

	public static boolean isValidMail(String email){
		boolean isValid;
		Pattern pattern = Pattern.compile("@+.+([info]|[org]|[com]|[it]|[net]|[eu])");
		Matcher match = pattern.matcher(email);
		isValid = match.matches();
		
		logger.debug("["+email+"]"+"isValidMail "+isValid);
		return isValid;
	}
	
	public static boolean isFull(String s){
		boolean isValid;
		Pattern pattern = Pattern.compile(".+");
		Matcher match = pattern.matcher(s);
		isValid = match.matches();
		logger.debug("["+s+"]"+"isFull "+isValid);
		return isValid;
	}
	public static boolean isTelephoneNumber(String number){
		boolean isValid;
//		Pattern pattern = Pattern.compile("^\\++39 ([\\d\\s]?\\d+[\\d\\s\\./_-]|[?])\\d+$");
		Pattern pattern = Pattern.compile("([\\d\\s]?\\d+[\\d\\s\\./_-]|[?])\\d+$");
		Matcher match = pattern.matcher(number);
		isValid = match.matches();
		logger.debug("["+number+"]"+"isDigit "+isValid);
		return isValid;
	}
	public static boolean isCap(String cap){
		boolean isValid;
		Pattern pattern = Pattern.compile("[0-9]{5}");
		Matcher match = pattern.matcher(cap);
		isValid = match.matches();
		logger.debug("["+cap+"]"+"isCap "+isValid);
		return isValid;
	}
	public static boolean isAnno(String anno){
		boolean isValid;
		Pattern pattern = Pattern.compile("[0-9]{4}");
		Matcher match = pattern.matcher(anno);
		isValid = match.matches();
		logger.debug("["+anno+"]"+"isAnno "+isValid);
		return isValid;
	}
	public static boolean isValidPassword(String password){
		boolean isValid;
		Pattern pattern = Pattern.compile("([a-z]|[A-Z]|[0-9]|[^ ]|[\\p{Punct}]){5,10}");
		//ammessi i caratteri speciali: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
		Matcher match = pattern.matcher(password);
		isValid = match.matches();
		logger.debug("["+password+"]"+"isValidPassword "+isValid);
		return isValid;
	}	
	public static void main (String[] args){
		RegexValidate.isValidPassword("pPp#223");
		//RegexValidate.isCap("123452");
	}
}
